
import React from 'react';
// import { useRouter } from 'next/router';
import Image from 'next/image';
import fetch from 'node-fetch'

export default function Classify(props: any) {
  console.log(props)
  return (
    <div className='classify-container'>
      <span className='w-full'>classify type: </span>
      <span>{props.type}</span>
      <Image
        src="https://fanyi-cdn.cdn.bcebos.com/static/translation/widget/translate/output/img/short-banner1_edeef70.png"
        alt="Picture of the author"
        width={250}
        height={100}
      />
    </div>
  )
}


export const getStaticPaths = async () => {
  // let res = await fetch('http://localhost:3000/api/movie');
  // let data = await res.json();
  let data = {
    "status": 0, "data": {
      "films": [
        { "filmId": 5268, "name": "送你一朵小红花" },
        { "filmId": 5257, "name": "拆弹专家2" },
        { "filmId": 5299, "name": "缉魂" },
        { "filmId": 5291, "name": "心灵奇旅" },
        { "filmId": 5279, "name": "温暖的抱抱" },
        { "filmId": 5295, "name": "许愿神龙" },
        { "filmId": 5301, "name": "叱咤风云" },
        { "filmId": 4922, "name": "大红包" },
        { "filmId": 5311, "name": "武汉日夜" },
        { "filmId": 4836, "name": "紧急救援" }]
    }
  };
  let paths = data.data.films.map((item: any) => {
    return { params: { type: `${item.filmId}` } }
  })
  // 传递所有包含[type]的数组给getStaticProps的context
  return {
    paths: [...paths],
    /**
     * false 匹配不到的路径直接返回默认的404页面
     * true 后备页面
     */
    fallback: false
  }
}

export const getStaticProps = async (context: any) => {
  const { params: { type } } = context;
  let res = await fetch(`https://m.maizuo.com/gateway?filmId=${type}`);
  let data = await res.json();
  return {
    props: {
      title: '静态化',
      data,
      type
    }
  }
}
